package com.johnnyyin.rockysocket;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.johnnyyin.librockysocket.ThreadPoolTest;

import org.w3c.dom.ProcessingInstruction;

import java.util.Locale;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'rockysocket' library on application startup.
    static {
        System.loadLibrary("rockysocket");
    }

    private int count = 0;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            count++;
            ((TextView)findViewById(R.id.sample_text)).setText(String.format(Locale.ENGLISH, "handle message %d times", count));
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        new Thread() {
            @Override
            public void run() {
                super.run();
                ThreadPoolTest threadPoolTest = new ThreadPoolTest(new ThreadPoolTest.ThreadPoolTestListener() {
                    @Override
                    public void onUnsolicited() {
                        mHandler.sendEmptyMessage(0);
                    }
                });
                threadPoolTest.stringFromJNI();
            }
        }.start();
    }
}
